package initalize

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"right/config"
	"right/global"
)

func InitMysql() {
	var err error
	sq := config.AppConf.MySQLConfig
	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", sq.User, sq.Pass, sq.Host, sq.Port, sq.MysqlDb)
	global.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("mysql link fail")
	}
	log.Println("mysql link success")
}
